package com.rmb.controller;

import com.rmb.annotation.SystemLog;
import com.rmb.client.EngineServiceClient;
import com.rmb.util.ConditionQuery;
import com.rmb.enums.LogType;
import com.rmb.service.TaskConditionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author 段段
 * @PackageName: com.rmb.controller
 * @ClassName: TaskConditionController
 * @Description:
 * @data: 2021/1/10 19:12
 **/
@RestController
@RequestMapping("/findSql")
public class TaskConditionController {

    @Autowired
    private TaskConditionService conditionService;



    /**
     * 执行任务,拼接sql
     * @param jsonString 用于拼接sql的前端json串
     * @return
     */
    @GetMapping("/ConditionQuery")
    @SystemLog(description = "执行任务，拼接sql",type = LogType.SELETE)
    public ConditionQuery conditionQuery(String jsonString){
        /*查询结果*/
        List<Map<String, Object>> map = conditionService.conditionQuery(jsonString);

        /*判断是否有数据*/
        if (map.size() == 0 || map == null){
            return new ConditionQuery(false,null);
        }
        return new ConditionQuery(true,map);
    }

    /**
     *
     * @param jsonString 用于拼接sql的前端json串
     * @param id 规则引擎id
     * @return
     */
    @GetMapping("/ConditionQueryEngine")
    @SystemLog(description = "执行任务，拼接sql",type = LogType.SELETE)
    public ConditionQuery conditionQuery(String jsonString,Long id){
        /*查询结果*/
        List<Map<String, Object>> map = conditionService.conditionQuery(jsonString,id);

        /*判断是否有数据*/
        if (map.size() == 0 || map == null){
            return new ConditionQuery(false,null);
        }
        return new ConditionQuery(true,map);
    }

    /**
     * @param jsonString 用于拼接sql的前端json串
     * @param id  规则引擎id
     * @param jsonJoin  联查
     * @return
     */

    @GetMapping("/ConditionQueryEngineJoin")
    @SystemLog(description = "执行任务，拼接sql",type = LogType.SELETE)
    public ConditionQuery conditionQuery(String jsonString,Long id,String jsonJoin){
        /*查询结果*/
        List<Map<String, Object>> map = conditionService.conditionQuery(jsonString,id,jsonJoin);
        /*判断是否有数据*/
        if (map.size() == 0 || map == null){
            return new ConditionQuery(false,null);
        }
        return new ConditionQuery(true,map);
    }
}
